package jmind.asteroidea.plugin.spring;

import jmind.asteroidea.proxy.*;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * description:
 *
 * @author weibo.xie
 * @date:2022/7/7 上午11:48
 */
public class AsteroideaInterfaceProxyFactoryBean implements FactoryBean, ApplicationContextAware {
    private ApplicationContext applicationContext;
    /**
     * 勿删，看似没用
     */
    private Class asteroideaInterfaceClass;
    private AsteroideaProxyEnum proxyEnum;

    public AsteroideaProxyEnum getProxyEnum() {
        return proxyEnum;
    }

    public void setProxyEnum(AsteroideaProxyEnum proxyEnum) {
        this.proxyEnum = proxyEnum;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Override
    public Object getObject() throws Exception {
        return AbstractAsteroideaInterfaceProxy.create(proxyEnum,asteroideaInterfaceClass,applicationContext).getProxy();
    }

    @Override
    public Class<?> getObjectType() {
        return asteroideaInterfaceClass;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public Class getAsteroideaInterfaceClass() {
        return asteroideaInterfaceClass;
    }

    public void setAsteroideaInterfaceClass(Class asteroideaInterfaceClass) {
        this.asteroideaInterfaceClass = asteroideaInterfaceClass;
    }
}
